import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JPanel;


public class MapDrawing extends JPanel{
		Dungeon dungeon;
		
		int tileSize = 10;
		
		public MapDrawing() {
			this.dungeon = Main.dungeon;
		}
		protected void paintComponent (Graphics g) {
			super.paintComponent(g);
			
			ImageIcon aWall = new ImageIcon("wall.jpg");
			ImageIcon aFloor = new ImageIcon("floor.jpg");
			
			Image wall = aWall.getImage();
			Image floor = aFloor.getImage();
			
			Room[][] rooms = dungeon.getRooms();
			Tile[][] tiles;
			//draws all the rooms
			for(int x = 0; x < dungeon.getWidth(); x++) {
				for(int y = 0; y < dungeon.getHeight(); y++) {
					tiles = rooms[x][y].getTiles();
					//draws a room
					for(int i = 0; i < rooms[x][y].getMaxWidth(); i++) {
						for(int j = 0; j < rooms[x][y].getMaxHeight(); j++) {
							if(tiles[i][j].isWall() == false) {
								g.drawImage(floor, i*tileSize+x*tileSize*(rooms[x][y].getMaxWidth()), j*tileSize+y*tileSize*(rooms[x][y].getMaxHeight()), tileSize, tileSize, this);
							}
							else {
								g.drawImage(wall,  i*tileSize+x*tileSize*(rooms[x][y].getMaxWidth()), j*tileSize+y*tileSize*(rooms[x][y].getMaxHeight()), tileSize, tileSize, this);
							}
						}
					}
				}
			}
			
		}

}
